<?php

/**
 *
 *
 * @version $Id$
 * @copyright 2013
 */

namespace com\org\web\tpl\utils {
	class Property {
		protected $properties = NULL;
		/**
		 * Constructor
		 * @access protected
		 */
		function __construct() {

		}

		public function __get($propertyName) {
		    if(!array_key_exists($propertyName, $this->properties))
		        throw new \Exception("Invalid property \"$propertyName\"!");
		    if(method_exists($this, "get" . $propertyName))
				return Reflector::invokeMethod($this, "get" . $propertyName, array());
		    else
		        return $this->properties[$propertyName];
		}

		public function __set($propertyName, $value) {
		    if(!array_key_exists($propertyName, $this->properties))
		        throw new \Exception("Invalid property \"$propertyName\"!");
		    if(method_exists($this, "set" . $propertyName))
				return Reflector::invokeMethod($this, "set" . $propertyName, array($value));
		    else
		        $this->properties[$propertyName] = $value;
		}

		public function __isset($propertyName) {
		    return isset($this->properties[$propertyName]);
		}

		public function __unset($propertyName) {
		    unset($this->properties[$propertyName]);
		}

		public function __destruct()  {
			if (isset($this->properties))
				unset($this->properties);
		}
	}
}
?>